<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      label-width="90px"
    >
      <el-form-item label="审核状态" prop="apstatus">
        <el-select
          v-model="queryParams.apstatus"
          placeholder="请选择审核状态"
          clearable
          @change="handleQuery"
        >
          <el-option
            v-for="dict in dict.type.apstatus"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="companyList">
      <el-table-column
        label="单位名称"
        align="center"
        prop="cname"
        fixed="left"
        min-width="200"
      />
      <el-table-column
        label="所属行业"
        align="center"
        prop="industry"
        width="100"
      >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.industry" :value="scope.row.industry" />
        </template>
      </el-table-column>
      <el-table-column
        label="单位等级"
        align="center"
        prop="levels"
        width="100"
      >
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.company_level"
            :value="scope.row.levels"
          />
        </template>
      </el-table-column>
      <el-table-column
        label="单位类型"
        align="center"
        prop="comtype"
        width="100"
      >
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.company_type"
            :value="scope.row.comtype"
          />
        </template>
      </el-table-column>
      <el-table-column
        label="单位地址"
        align="center"
        prop="address"
        min-width="180"
      />
      <el-table-column
        label="单位联系人"
        align="center"
        prop="contactName"
        width="100"
      />
      <el-table-column
        label="联系电话"
        align="center"
        prop="phone"
        width="120"
      />
      <el-table-column
        label="申请人"
        align="center"
        prop="apuser"
        width="120"
      />
      <el-table-column
        label="申请时间"
        align="center"
        prop="apcreateTime"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.apcreateTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="审核状态"
        align="center"
        prop="apstatus"
        width="120"
      >
        <template slot-scope="{ row }">
          <div class="disFlxCC">
            <dict-tag
              :options="dict.type.apstatus"
              :value="String(row.apstatus)"
            />
          </div>
        </template>
      </el-table-column>
      <el-table-column
        label="审核时间"
        align="center"
        prop="apupdateTime"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.apupdateTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        width="120px"
        fixed="right"
      >
        <template slot-scope="{ row }">
            <!-- 1待平台审核 2待渠道审核 -->
          <el-button
            v-if="(userInfo.userType == 0 && row.apstatus == 1) || (userInfo.userType == 1 && row.apstatus == 2)"
            size="mini"
            type="text"
            @click="openDialog(row)"
            >入驻审核</el-button
          >
          <el-button
            v-else
            size="mini"
            type="text"
            @click="openDialog(row)"
            >查看详情</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <DetailsDialog :show="open" :companyId="companyId" @close="open = false" @upList="getList" />
  </div>
</template>

<script>
import { companyAplist } from "@/api/company/company";
import DetailsDialog from "../company/detailsDialog.vue";

export default {
  name: "CompanyApList",
  dicts: ["industry", "company_level", "company_type", "apstatus"],
  components: {
    DetailsDialog
  },
  computed: {
    userInfo() {
      return this.$store.state.user.userInfo;
    },
  },
  data() {
    return {
      loading: true,
      // 总条数
      total: 0,
      // 单位表格数据
      companyList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        apstatus: "",
      },
      open: false,
      companyId: "",
    };
  },
  created() {
    this.getList();
  },
  activated() {
    this.getList();
  },
  methods: {
    locationSure (val) {
      // 定位地址
      console.log(val, '------------------------------>')
    },
    /** 查询单位列表 */
    getList() {
      this.loading = true;
      companyAplist(this.queryParams).then((response) => {
        this.companyList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 打开详情
    openDialog(row){
      this.companyId = row.id
      this.open = true
    }
  },
};
</script>
